<div class="fsh-pop">
    <div id="add_form" class="layui-form" lay-filter="example">
         <input type="hidden" name="user_id" id="role_id" value="<%=user_id%>"/>
        <input type="hidden"  id="sex_hidden" value="<%=sex%>"/>
       <input type="hidden"  value="<%=teamName%>" name="teamName"/>
       <input type="hidden"  value="<%=departmentName%>" name="departmentName"/>
       <input type="hidden"  id="team_hidden" value="<%=team%>"/>
       <input type="hidden"  id="department_hidden" value="<%=department%>"/>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>姓名</label>
            <div class="layui-input-block">
                <input name="nickname" maxlength="20" lay-verify="required"
                value="<%=nickname%>" class="layui-input">
            </div>
        </div>
          <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>性别</label>
            <div class="layui-input-block">
              <input type="radio" name="sex" value="0" title="男" id="sex_man" >
              <input type="radio" name="sex" value="1" title="女" id="sex_women">
            </div>
          </div>
<!--         <div class="layui-form-item layui-form-text">-->
<!--            <label class="layui-form-label"><i>*</i>职位</label>-->
<!--            <div class="layui-input-block">-->
<!--                <input name="job" maxlength="20" lay-verify="required" value="<%=job%>" class="layui-input">-->
<!--            </div>-->
<!--        </div>-->
         <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>电话</label>
            <div class="layui-input-block">
                <input name="phone" maxlength="20"  value="<%=phone%>" class="layui-input" lay-verify="phone|required">
            </div>
        </div>
         <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>邮箱</label>
            <div class="layui-input-block">
                <input name="email" maxlength="20"  value="<%=email%>" class="layui-input" lay-verify="email">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-block">
                <div class="layui-upload">
              <button type="button" class="layui-btn" id="upload_header">上传头像</button>
              <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" src="<%=photo%>">
                <p id="demoText"></p>
                 <input type="hidden" name="photo" id="photo" value="<%=photo%>">
              </div>
            </div>
        </div>
        </div>
    </div>
</div>
<style type="text/css">
#demo1
{
  width: 100px;
  height: 100px;
  border: 1px solid #e3e3e3;
}
</style>
<script type="text/javascript">
var defaultSelect = $("#parent_id").val();
var sex = $("#sex_hidden").val()
if (sex==1) {
  $("#sex_women").attr('checked',true);
}else{
  $("#sex_man").attr('checked',true);
}

var selectTeam = $('#team_hidden').val();
var selectDeaprtment = $('#department_hidden').val();
layui.use(['form','upload'], function () {
var form = layui.form;
var upload = layui.upload;
$('#select1').html();
$.ajax({
    url: context + '/api/team/list',
    dataType: 'json',
    type: 'get',
     success:function(data){

        if(data!=undefined&&data!=null&&data!=""){
        var list = data.data;
        var html="<option value=''>请选择所属团队</option>";
            for(var i=0;i<list.length;i++){
                 html+="<option value="+list[i]["k"]+">"+list[i]["v"]+"</option>";
             }
               $("#select1").append(html);
               $("#select1").val(selectTeam);
               form.render("select");
        }


    }
});
form.on('select(select1)', function(data){
  $('#team_hidden').val(data.elem[data.elem.selectedIndex].text);

});
// 所属部门
$('#select2').html();
$.ajax({
    url:context+'/api/department/list',
    dataType:'json',
    type:'get',
     success:function(data){

        if(data!=undefined&&data!=null&&data!=""){
        var list = data.data;
        var html="<option value=''>请选择所属团队</option>";
            for(var i=0;i<list.length;i++){
                 html+="<option value="+list[i]["k"]+">"+list[i]["v"]+"</option>";
             }
               $("#select2").append(html);
               $("#select2").val(selectDeaprtment);
               form.render("select");
        }


    }
});
form.on('select(select2)', function(data){
  $('#department_hidden').val(data.elem[data.elem.selectedIndex].text);

});
// 上传图片
var uploadInst = upload.render({
elem: '#upload_header'
,url: context+'/api/fileupload/add'
,field:'attach'
,done: function(res){
  if(res.success){
     $('#demo1').attr('src', res.link);
     $('#photo').val(res.link);
  }else{
    layui.layer.msg('上传失败');
  }
  //上传成功
}
,error: function(){
  //演示失败状态，并实现重传
  var demoText = $('#demoText');
  demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
  demoText.find('.demo-reload').on('click', function(){
    uploadInst.upload();
  });
}
});

});


</script>
